<template>
	<gui-page ref="guiPage" :customHeader="true">
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left" :title="$t('distributedEnter.scanRecord')"></nav-bar-custom>
		</template>
		<template v-slot:gBody>
			<view v-if="data.scanList.length == 0" class="noticeHooks">
				{{ data.scanList.length == 0 ? $t('stockManage.notAvailable') : $t('stockManage.without') }}
			</view>
			<template v-for="(el, i) in data.scanList" :key="`${el.storeId}` + `${i}`" v-else>
				<view v-for="(item, index) in el.arr" :key="`${item.barcode}` + `${index}`" class="record-card">
					<uni-icons class="close-icons" type="closeempty" color="#9C9C9C" size="30"
						@click="handelClosePopup(i, index, item)"></uni-icons>
					<view class="card-mini-head">
						<view class="title-line"></view>
						<text>{{ $t('translationImage.serialNumber') }}：{{ i }}{{ el.arr.length - index }}</text>
					</view>
					<view class="custom-card-itemOne">
						<text class="item-info-title">{{ $t('distributedOut.barcode') }}：</text>{{ item.barcode }}
					</view>
					<view class="custom-card-itemOne">
						<text class="item-info-title">{{ $t('distributedEnter.materialName') }}：</text>{{
							item.materialName }}
					</view>
					<view class="custom-card-itemOne">
						<text class="item-info-title">{{ $t('distributedEnter.materialCode') }}：</text>{{
							item.materialCode }}
					</view>
					<view class="custom-card-itemOne">
						<text class="item-info-title">{{ $t('distributedEnter.scannedQuantity') }}：</text>{{
							item.currentQty }}
					</view>
					<view class="custom-card-itemOne">
						<text class="item-info-title">{{ $t('distributedOut.location') }}：</text>{{ item.locationCode }}
					</view>
					<view v-if="item.repaetTypeCode != null && item.repaetTypeCode == 'ReceivingForPlay'"
						class="custom-card-itemOne">
						<text class="item-info-title">{{ $t('stockManage.giveQty') }}：</text>{{ item.currentQty }}
					</view>
				</view>
			</template>
		</template>
	</gui-page>
</template>

<script setup>
import { navigate } from '@/utils/routerSkip.js';
import { useStore } from "vuex";
import { watch } from "vue";
import { basPdaOperationLogFn } from '@/utils/index.js';
import { OPERATION_DEL, OPERATION_LOOK } from '@/constant/index.js'
import { cancelOccupy } from '@/api/api.js'
import {computed,reactive,onMounted} from 'vue';
//国际化引入
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
// 接受来自父组件的传参
const props = defineProps({
	id: String,
});
let data = reactive({
	id: props.id,// 上级界面传过来的id
	scanList: [],
})
let store = useStore();
// fqc扫描条码
data.scanList = computed(() => {
	return store.state.stockManage.wmsScanList
})
onMounted(() => {
	try {
		let inputParameter = '无'
		let returnParameter = JSON.stringify(data.scanList)
		let operationPicture = '来料入库'
		let callInterface = '无'
		let opertionParmes = {
			inputParameter,
			returnParameter,
			operationPicture,
			callInterface,
			responseCode: '无',//返回状态
			errorMessage: '无',//错误信息
			isPass: 'Y',//是否成功 Y N
			operationType: OPERATION_LOOK,
			module: 'WMS',
			source: "PDA",
		}
		basPdaOperationLogFn(opertionParmes)
	} catch (error) {
	}
})
const handelClosePopup = (i, index, item) => {
	let parmes = {
		locationName:item.wmsMaterialCapacity.locationName,
		locationCode: item.locationId,
		materialCode: item.materialCode,
		id: item.wmsMaterialCapacity.id,
		barcode: item.barcode
	}
	// 扫码取消的时候调用接口取消占用的库位
	cancelOccupy([parmes]).then(res => {
		try {
			let inputParameter = JSON.stringify(parmes)
			let returnParameter = JSON.stringify(res)
			let operationPicture = '来料入库'
			let callInterface = res.rquestUrl
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: res.code,//返回状态
				errorMessage: res.msg,//错误信息
				isPass: res.code == 0 ? 'Y' : 'N',//是否成功 Y N
				operationType: OPERATION_SCAN,
				module: 'WMS',
				source: "PDA",
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) {
		}
		if (res.code == 0) {
			uni.showToast({ title: t('fixedAssets.description'), icon: 'none', })
			// 标记当前的索引 去删除相对应的数据
			let num = {
				i: i,
				index: index
			}
			store.dispatch('stockManage/delWmsScanListItem', num)
		} else {
			uni.showToast({ title: res.msg, icon: 'none', })
		}
	})
}
</script>

<style>
.record-card {
	position: relative;
}
</style>
